﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Local.Service.RAS;
using Windows.Storage;

namespace Local.Service
{
    public class LocalGlobalService
    {
        public static async Task SaveSysWebInfo(IList<SysWebInfo> sysWebInfos)
        {
            Utils.CheckFolder("global");
            await XmlHelper.Serialize(sysWebInfos, @"global\webinfos");
        }

        public static async Task<IList<SysWebInfo>> GetSysWebInfos()
        {
            return await XmlHelper.Deserialize<IList<SysWebInfo>>(@"global\webinfos");
        }

        public static async Task<SysWebInfo> GetSysWebInfo(string webflag)
        {
            var list = await XmlHelper.Deserialize<IList<SysWebInfo>>(@"global\webinfos");
            var item = from p in list
                       where p.webflag.Equals(webflag)
                       select p;
            if (item.Any())
            {
                return item.First();
            }
            return null;
        }

        public static async Task SaveIndexGroup(IList<ArticleInfo> list)
        {
            Utils.CheckFolder("global");
            await XmlHelper.Serialize(list, @"global\index");
        }

        public static async Task<IList<ArticleInfo>> GetIndexGroup()
        {
            return await XmlHelper.Deserialize<IList<ArticleInfo>>(@"global\index");
        }
    }
}
